package adl

import (
	"encoding/json"
	"log"

	"github.com/gogf/gf/os/glog"
	"github.com/gogf/gf/util/gconv"
)

type StringJson map[string]interface{}

type Ws struct {
	// Ws *ghttp.WebSocket
}

// func (ws *Ws) SentWithFlag(flag string, inf interface{}) []byte {
func SentWithFlag(flag string, inf interface{}) []byte {

	// infBack, err := gjson.Encode(phpMap{command: inf})
	// infBack, err := gjson.Encode(g.NewVar(stringJson{command: inf}))

	glog.Println(`--------------- ws output ---------------`)
	glog.Println(gconv.String(inf))
	infBack, err := json.Marshal(StringJson{flag: inf})
	if err != nil {
		// glog.Println(err)
		// ws.Sent([]byte(err.Error()))
		log.Fatalln(`err JSON Marshal:`, err, `!`)
		return []byte(err.Error())
	}
	glog.Println(`--------------- ws output generated ---------------`)
	glog.Println(string(infBack))
	// ws.Sent(infBack)
	return infBack
	// return infBack
	// gredis.Redis
	// r.Response.Write(os.Args[1])
}

func (ws *Ws) Sent(inf []byte) {
	// if err := ws.Ws.WriteMessage(1, inf); err != nil {
	// glog.Println(`ws sent err:`, err, `!`)
	// }
}
